import Tiao1 from "../chess/mahjong/tiao/1";
import Tiao2 from "../chess/mahjong/tiao/2";
import Tiao3 from "../chess/mahjong/tiao/3";
import Tiao4 from "../chess/mahjong/tiao/4";
import { FIGHTERS_MAX } from "../render";

export default class Turn {
    constructor() {
        this.reset();
    }

    reset() {
        this.index = 0;
        this.timeLeft = 300;
        this.totalEnemiesCount = 0;
        this.generatedEnemiesCount = 0;
        this.preparing = true; // 准备阶段
    }

    next() {
        ++this.index;
        this.timeLeft = 300;
        this.totalEnemiesCount = 5;
        this.generatedEnemiesCount = 0;
        this.preparing = true;
        // 选择棋子
        this.selectFighter();
    }

    selectFighter() {
        // todo 选择棋子
        const allTiles = [new Tiao1(), new Tiao2(), new Tiao3(), new Tiao4()];
        let selectedFighter = allTiles[Math.floor(Math.random() * allTiles.length)];

        // GameGlobal.databus.handCards.push(selectedFighter);
        // if (GameGlobal.databus.fighters.length < 1) {
        //     GameGlobal.databus.fighters.push(selectedFighter);
        //     GameGlobal.databus.handCards.pop();
        // }
        if (GameGlobal.databus.fighters.length < FIGHTERS_MAX) {
            GameGlobal.databus.fighters.push(selectedFighter);
        }
        else {
            GameGlobal.databus.handCards.push(selectedFighter);
        }
        this.preparing = false;
        this.countDown();
    }

    countDown() {
        this.timeLeft--;
        if (this.timeLeft <= 0) {
            this.preparing = false;
        }
    }


}
